import wx

try:
    from agw import balloontip as BT
except ImportError: # if it's not there locally, try the wxPython lib.
    import wx.lib.agw.balloontip as BT


class Literate():
    def __init__(self, hints):
        
        titlefont = wx.Font(9, wx.SWISS, wx.NORMAL, wx.BOLD, True)
        hintfont = wx.Font(8, wx.SWISS, wx.ITALIC, wx.NORMAL, False)
        
        for option, values in hints.iteritems():
            (name, hint) = values[0:2]
            
            try:
                widget = getattr(self, name)
            except AttributeError:
                continue
            
            try:
                default = values[2]
            except IndexError:
                pass
            else:
                try:
                    widget.SetValue(default)
                except TypeError:
                    widget.SetValue(bool(default))
                
           
            title = "Option: -%s\nWidget: %s" %(option, name)
            
            tipballoon = BT.BalloonTip(topicon=None, toptitle=title,
                       message=hint, shape=BT.BT_ROUNDED,
                       tipstyle=BT.BT_LEAVE)
            
            # Set The Target
            tipballoon.SetTarget(widget)
            # Set The Balloon Colour
            tipballoon.SetBalloonColour(None)
            # Set The Font For The Top Title
            tipballoon.SetTitleFont(None)
            # Set The Colour For The Top Title
            tipballoon.SetTitleColour(wx.RED)
            # Set The Font For The Tip Message
            tipballoon.SetMessageFont(hintfont)
            # Set The Colour For The Tip Message
            tipballoon.SetMessageColour(None)
            # Set The Delay After Which The BalloonTip Is Created
            tipballoon.SetStartDelay(1000)
    

